//package pl.com.like.sequoia.web.search;
//
//import java.io.File;
//import java.text.MessageFormat;
//
//import org.apache.wicket.PageParameters;
//import org.apache.wicket.markup.html.WebPage;
//import org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
//import org.apache.wicket.spring.injection.annot.SpringBean;
//import org.apache.wicket.util.resource.FileResourceStream;
//import org.apache.wicket.util.resource.IResourceStream;
//import org.wicketstuff.annotation.mount.MountPath;
//
//import pl.com.like.sequoia.model.bio.BioObjectHandler;
//import pl.com.like.sequoia.web.service.ISearchService;
//import pl.com.like.sequoia.web.vo.SearchType;
//
///**
// * Bean handles search requests. Tries to find object in database. if not find, return empty page
// * 
// * @author Pawel Wolanski
// * 
// */
//@MountPath(path = "/get")
//public class SearchHandlerPage extends WebPage {
//
//	@SpringBean
//	private ISearchService searchService;
//
//	public SearchHandlerPage(PageParameters parameters) {
//		String objectType = parameters.getString("type");
//		String idObject = parameters.getString("id");
//		if (idObject != null) {
//			SearchType type = SearchType.PDB.toEnum(objectType);
//			BioObjectHandler bioObj = searchService.findBioObject(idObject, type);
//			if (null != bioObj.getPath() && (new UpFile(bioObj.getPath()).exists())) {
//				UpFile file = new UpFile(bioObj.getPath());
//				IResourceStream stream = new FileResourceStream(file);
//				getRequestCycle().setRequestTarget(
//						new ResourceStreamRequestTarget(stream, generateFilename(idObject, type)));
//			}
//		}
//	}
//
//	/**
//	 * generates human readable file name.
//	 * 
//	 * @param idObject
//	 * @param type
//	 * @return
//	 */
//	public String generateFilename(String idObject, SearchType type) {
//		String name = "";
//		switch (type) {
//			case PDB:
//				name += "pdb";
//				break;
//			// case FASTA:
//			// name += "fasta";
//			// break;
//			// case GENBANK:
//			// name += "gb";
//			// break;
//		}
//		name = MessageFormat.format("{0}.{1}.gz", idObject, name);
//		return name;
//	}
//
//	public ISearchService getSearchService() {
//		return searchService;
//	}
//
//	public void setSearchService(ISearchService searchService) {
//		this.searchService = searchService;
//	}
// }
